package com.hspedu.reflection.homework;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class HomeWork02 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class<?> cls = Class.forName("java.io.File");

        Constructor<?>[] declaredConstructors = cls.getDeclaredConstructors();
        for (Constructor<?> declaredConstructor : declaredConstructors) {
            System.out.println("declaredConstructor=>" + declaredConstructor);
        }

        Constructor<?> constructor = cls.getConstructor(String.class);
        String fileFullPath = "E:\\myNew.txt";
        Object file = constructor.newInstance(fileFullPath);

        Method newFile = cls.getMethod("createNewFile");
        newFile.invoke(file);

        System.out.println(file.getClass());
        System.out.println("创建文件成功：" + fileFullPath);
    }
}
